import { ref, watch, reactive, getCurrentInstance } from 'vue'
import { Search, Plus } from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
import request from '@/utils/request'
import buttonAction from './component/buttonAction'
import $button from '@/button'
import tableComp from './component/tableComp'
const proxy = getCurrentInstance();
const confNameMap = reactive({
    commissionRate: '分佣规则',
    withdrawalLimit: '每日提现上限',
    receivingAccount: '收款账户'
})

export const operationItem = reactive({
    defaultSearch: false,//默认搜索按钮
    defaultRefresh: false,//默认重置按钮
    customTableHeader: false,//
    SearchItem: [
    ],
    menuArray: [
    ]
})

export const tableItem = reactive({
    select: false,
    index: !true,
    tree: true,
    expandAll: true,
    align: 'center',
    column: [
        {
            label: '名称',
            prop: 'name',
            align: 'center',
            width: '200'
        },
        {
            label: '内容',
            prop: 'content',
            align: 'center',
            component: tableComp
        },
        {
            label: '操作',
            prop: 'action',
            align: 'center',
            component: buttonAction,
            width: '200'
        }
    ],
    pageInfo: {
        request: {
            'nickName': '',
            'typeCodeList': [],
            'pageDomain': {
                'pageNum': '1',//分页页面数
                'pageSize': '10000',//分页页面数据大小
                'orderByColumn': '',//搜索参数
                'isAsc': '',//搜索参数
                'reasonable': ''//搜索参数
            }
        },
        url: '',//分页路由，不传的话需要传入自定义的分页函数paging 传入时定义的分页函数paging会失效 ///conf/all
        method: 'GET',//分页请求方法，不传默认为POST
        pagesClose: true,//是否关闭分页
        // 分页函数paging
        paging: function () {
            tableItem.loading = true
            confAllApi().then(res => {
                let confAllDataArray = []
                let confTypeArray = Object.keys(res.data)
                for( let i=0; i<confTypeArray.length; i++) {
                    let confItem = {
                        typeCode: '',
                        name: '',
                        content: {}
                    }
                    confItem.typeCode = confTypeArray[i]
                    confItem.name = confNameMap[confItem.typeCode]
                    confItem.content = res.data[confItem.typeCode]
                    confAllDataArray.push(confItem)
                }
                tableItem.tableData.data = confAllDataArray
                tableItem.loading = false
            }).catch(() => { tableItem.loading = false })
        }
    },
    // 分页数据 自定义分页函数paging时需要把值赋给tableData
    tableData: {
        total: '',//分页总计
        // 分页数据
        data: []
    },
    // 操作栏按钮
    btnArray: [
        {
            label: '查看',
            type: 'primary',
            plain: true,//镂空按钮  优先文字按钮
            text: true,//文字按钮
            customParameters: 'view',//自定义函数参数
            show: true,//是否显示
            // 按钮方法
            handle: function (row) {
            }
        },
    ],
    moreBtnArrayText: '',
    moreBtnArray: [],
    // 选择框触发
    selectChange: function (row) {
    },
}
)

// 获取全部参数配置内容
export function confAllApi(dataRequest) {
    return request({
        url: '/conf/all',
        method: 'GET',
        data: dataRequest
    })
}




